<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>合同分期</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="css/addContract.css" />


<script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
<script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript" src="layer/layer.js"></script>
<script src="laydate/laydate.js"></script>
    <script type="text/javascript" src="js/handlebars-v3.0.3.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/mui.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            var hosturl = "http://"+ window.location.host + "/"+ window.location.pathname.split('/')[1];
            function GetQueryString(name)
            {
                var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if(r!=null)return  unescape(r[2]); return null;
            };
            var content = document.getElementById("content");
            mui.ajax(hosturl+"/payLog/byId", {
                data: {
                    "contractId":GetQueryString("id")
                },
                dataType: "json",
                type: "post",
                timeout: 10000,
                success: function (datas) {
                    if (datas.status != "ok") {
                        alert(datas.description);
                        window.location.href = hosturl+'/payRemind.html?id='+GetQueryString("id");
                    } else {
                        for(var i = 0;i < GetQueryString("num"); i++) {
                            var str = datas.body[i].paidTime + "";
                            var html = document.getElementById("content").innerHTML;
                            content.innerHTML= html+"<div class='add-detail-date' style='margin-top:10px;'>第"+(i+1)+"期：<input type='text' id='paidTime"+i+"'  value='"+datas.body[i].paidTime+"' class='laydate-icon' onclick='laydate()'/><input type='text'id='money"+i+"'  value='"+datas.body[i].money+"' class='laydate-icon' />";
                            var html2 = document.getElementById("content").innerHTML;
                            content.innerHTML = html2 + "<input type='button' class='add-receive' style='height:23px;width:70px;line-height:20px;font-size:12px;' value='保存' onClick='btn("+datas.body[i].id +"," + datas.body[i].contractId + "," + i +");' /></div>";
                        }
//                        var html1 = document.getElementById("content").innerHTML;
//                        content.innerHTML=html1+"<div class='' style='display:none'>占位：<input type='text' class='laydate-icon' onclick='laydate()'/> </div><div class=''><input type='button' id='btn'  class='add-receive' style='height:23px;width:84px;line-height:20px;font-size:12px;' value='保存' /> </div> "
                    }
                },
                error: function (xhr, type, errorThrown) {
                    console.log(type);
                }
            });
        });
    </script>

</head>

<body>
    <div class="addMain" id="content" style="margin:0px auto;width:1000px;height:200px;">
        <!--<div class="add-detail-date" style="margin-top:10px;">-->
        	<!--第1期：<input type="text" class="laydate-icon" onclick="laydate()"/>-->
        <!--</div>-->
        <!--<div class="" style="display:none">-->
        	<!--占位：<input type="text" class="laydate-icon" onclick="laydate()"/>-->
        <!--</div>-->
        <!--<div class="">-->
        	<!--<input type="button"  class="add-receive" style="height:23px;width:84px;line-height:20px;font-size:12px;" value="保存" />-->
        <!--</div>  -->
    </div>
</body>
</html>
<script type="text/javascript">
    var hosturl = "http://"+ window.location.host + "/"+ window.location.pathname.split('/')[1];
    function  btn(Id,ContractId,i) {
//       alert(id+" "+contractId+" "+i);
        var id = Id + "";
        var contractId = ContractId +"";
//        var ii = i + "";
        var money = document.getElementById("money"+i).value + "";
        var paidTime = document.getElementById("paidTime"+i).value + "";
        mui.ajax(hosturl+"/payLog/update", {
            data: {
                "id":id,
                "money":money,
                "remindTime":paidTime,
                "paidTime":paidTime,
                "contractId":contractId
            },
            dataType: "json",
            type: "post",
            timeout: 10000,
            success: function (datas) {
                if (datas.status != "ok") {
                   layer.msg(datas.description, function(){
                                });
//                    window.location.href = 'payRemind.html?id='+GetQueryString("id")+"&num="+GetQueryString("num");
                } else {
//                    alert("12");
//                    window.location.href = 'payRemind.html?id='+GetQueryString("id")+"&num="+GetQueryString("num");
                    layer.msg('保存成功', function(){
                });
                    window.location.reload();

                }
            },
            error: function (xhr, type, errorThrown) {
                console.log(type);
            }
        });
window.onload=function(){
	var oCheckbox=document.getElementById('checkbox1');
	var oDiv1=document.getElementById('div1');
	oCheckbox.addEventListener("click",function(){
		if(oCheckbox.checked==true){
			oDiv1.style.display='block';
			}
	   else {
			oDiv1.style.display='none';
	   	}}
		);

    }
	}
</script>
<script>
;!function(){
laydate({
   elem: '#demo'
})
}();
</script>
</body>
</html>
<div style="display:none">
	<script type="text/javascript">
	var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
//	document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F6f798e51a1cd93937ee8293eece39b1a' type='text/javascript'%3E%3C/script%3E"));
	</script>
	<script type="text/javascript">
        var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
//        document.write(unescape("%3Cspan id='cnzz_stat_icon_5718743'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s9.cnzz.com/stat.php%3Fid%3D5718743%26show%3Dpic2' type='text/javascript'%3E%3C/script%3E"));
    </script>
	</div>
